import { ElMessageBox } from "element-plus"

const showComfirm = (title, msg, callbackSuccess, callbackCancel, type) => {
	ElMessageBox.confirm(msg, title, {
		confirmButtonText: "OK",
		cancelButtonText: "Cancel",
		type: type,
	})
		.then(() => {
			if (callbackSuccess) {
				callbackSuccess()
			}
		})
		.catch(() => {
			if (callbackCancel) {
				callbackCancel()
			}
		})
}

const comfirm = {
	success: (title, msg, callbackSuccess, callbackCancel) => {
		showComfirm(title, msg, callbackSuccess, callbackCancel, "success")
	},
	info: (title, msg, callbackSuccess, callbackCancel) => {
		showComfirm(title, msg, callbackSuccess, callbackCancel, "info")
	},
	warning: (title, msg, callbackSuccess, callbackCancel) => {
		showComfirm(title, msg, callbackSuccess, callbackCancel, "warning")
	},
	error: (title, msg, callbackSuccess, callbackCancel) => {
		showComfirm(title, msg, callbackSuccess, callbackCancel, "error")
	},
}

export default comfirm
